﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace HungTrung
{
    public class Trung
    {
        private PictureBox _picturebox;
        private int _speed;

        private Timer timerFall;

        public static List<Trung> ListTrung = new List<Trung>();

        public int Top
        {
            set { _picturebox.Top = value; }
            get { return _picturebox.Top; }
        }

        public int Left
        {
            set { _picturebox.Left = value; }
            get { return _picturebox.Left; }
        }

        public int Speed
        {
            set { _speed = value; }
            get { return _speed; }
        }

        public Trung()
        {
            _picturebox = new PictureBox();
            _picturebox.Size = new Size(32, 32);
            _picturebox.SizeMode = PictureBoxSizeMode.StretchImage;
            _picturebox.Image = Properties.Resources.egg1;
            _picturebox.BackColor = Color.Transparent;
            

            _speed = 0;

            timerFall = new Timer();
            timerFall.Interval = 5;
            timerFall.Tick += new EventHandler(vitri);
            timerFall.Start();

            ListTrung.Add(this);
        }

        public void Add(Form form)
        {
            form.Controls.Add(_picturebox);
        }

        private void vitri(object sender, EventArgs e)
        {
            this.Top += _speed;

            kiemtrachamsan();
        }

        private void kiemtrachamsan()
        {
            if (this.Top > 520)
            {
                timerFall.Stop();
                deletetrung();
                ListTrung.Remove(this);
            }
        }

        public void deletetrung()
        {
            if (_picturebox.Parent != null)
            {
                _picturebox.Parent.Controls.Remove(_picturebox);
            }
        }
        public void taochatthai()
        {
            _picturebox.Image = Properties.Resources.shit1;
        }
    }
   
}
